package gateway.atguigu.gmall.product.controller;


import gateway.atguigu.gmall.common.result.Result;
import gateway.atguigu.gmall.model.product.BaseAttrInfo;
import gateway.atguigu.gmall.model.product.BaseCategory1;
import gateway.atguigu.gmall.model.product.BaseCategory2;
import gateway.atguigu.gmall.model.product.BaseCategory3;
import gateway.atguigu.gmall.product.service.MangeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController()
@RequestMapping("/admin/product")
@Api("商品基础开发接口")
public class BaseManageController {

    @Autowired
    private MangeService mangeService;

    /**
     * 保存平台属性方法
     * @param baseAttrInfo
     * @return
     */
    @PostMapping("saveAttrInfo")
   private Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        mangeService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    /**
     * 根据分类Id 获取平台属性数据
     * @param category1Id
     * @param category2Id
     * @param category3Id
     * @return
     */
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> attrInfoList(@PathVariable("category1Id") Long category1Id,
                                                   @PathVariable("category2Id") Long category2Id,
                                                   @PathVariable("category3Id") Long category3Id) {
        List<BaseAttrInfo> baseAttrInfoList = mangeService.getAttrInfoList(category1Id, category2Id, category3Id);
        return Result.ok(baseAttrInfoList);
    }










    /**
     * 查询所有的一级
     * @return
     */
    @GetMapping("/getCategory1")
    @ApiOperation("查询一级分类")
    public Result getCategory1 () {
       List<BaseCategory1> baseCategory1s  = mangeService.getCategory1();
        return Result.ok(baseCategory1s);
    }

    /**
     * 通过一级id查询二级数据
     * @param category1Id
     * @return
     */
    @GetMapping("/getCategory2/{category1Id}")
    @ApiOperation("查询二级的分类")
    public Result getCategory2 (@PathVariable("category1Id") Long category1Id) {
     List<BaseCategory2>  baseCategory2List =  mangeService.getCategory2(category1Id);
        return Result.ok(baseCategory2List);
    }

    /**
     * 通过二级id查询三级数据
     * @param category2Id
     * @return
     */
    @GetMapping("/getCategory3/{category2Id}")
    @ApiOperation("查询三级的分类")
    public  Result getCategory3(@PathVariable("category2Id") Long category2Id) {
        List<BaseCategory3>  baseCategory3s =  mangeService.getCategory3(category2Id);
        return Result.ok(baseCategory3s);
    }

}
